namespace OneWorks.Utils.FluentData
{
    using System;

    internal class QueryDynamicHandler<TEntity> : IQueryTypeHandler<TEntity>
    {
        private readonly DbCommandData _data;
        private readonly DynamicTypeAutoMapper _autoMapper;

        public bool IterateDataReader { get { return true; } }

        public QueryDynamicHandler(DbCommandData data)
        {
            this._data = data;
            this._autoMapper = new DynamicTypeAutoMapper(this._data.Reader.InnerReader);
        }

        public object HandleType(Action<TEntity, IDataReader> customMapperReader, Action<TEntity, dynamic> customMapperDynamic)
        {
            var item = this._autoMapper.AutoMap();
            return item;
        }
    }
}